<?php


namespace App\Http\Controllers\Admin;


use App\Model\Rules;
use App\Tool\Json;

class RulesController extends AuthCheckController
{

    /**
     * 路由列表
     * Create by Peter
     * 2019/08/26 11:17:56
     * Email:904801074@qq.com
     * @return false|string
     */
    function rule_list(){

        $list=Rules::orderBy('id');

        return Json::code(1,'success',paginate($list,request()->input('p',1)));

    }

    /**
     * 获取单个路由信息
     * Create by Peter
     * 2019/08/26 11:18:07
     * Email:904801074@qq.com
     * @param $id
     * @return false|string
     */
    function rule_info($id){

        $data=Rules::find($id);

        return Json::code(1,'success',$data);

    }


    function rule_update(){

        $post=request()->post();

        $id=$post['id']??null;


        Rules::updateOrCreate(['id'=>$id],$post);

        return Json::code(1,'success',$post);

    }


    function rule_delete(int $id){

        Rules::destroy($id);

        return Json::code(1,'success');

    }

}
